/*******************************************************************************
* AW9523B - driver
* 16 channel breath LED/GPIO extender controler
* by longcd
*******************************************************************************/

#ifndef _AW9523B_H
#define _AW9523B_H

//data type
typedef unsigned char aw_u8;

//pin define
typedef enum{
	AW_P10 = (aw_u8)0X20,
	AW_P11 = (aw_u8)0X21,
	AW_P12 = (aw_u8)0X22,
	AW_P13 = (aw_u8)0X23,
	AW_P00 = (aw_u8)0X24,
	AW_P01 = (aw_u8)0X25,
	AW_P02 = (aw_u8)0X26,
	AW_P03 = (aw_u8)0X27,
	AW_P04 = (aw_u8)0X28,
	AW_P05 = (aw_u8)0X29,
	AW_P06 = (aw_u8)0X2A,
	AW_P07 = (aw_u8)0X2B,
	AW_P14 = (aw_u8)0X2C,
	AW_P15 = (aw_u8)0X2D,
	AW_P16 = (aw_u8)0X2E,
	AW_P17 = (aw_u8)0X2F,
}AW_PIN;

//current set
typedef enum{
	Imax_4 = (aw_u8)0x00,	//37mA
	Imax_3 = (aw_u8)0x01,	//37mA * 3/4
	Imax_2 = (aw_u8)0x02,	//37mA * 2/4
	Imax_1 = (aw_u8)0x03,	//37mA * 1/4
}AW_IMAX;

//read ID: 0x23 fixed
#define AW9523_read_ID()	AW9523_readReg(0x10)

/*	set P0 mode GPIO/LED
 *	mode	: bit7~0 ---- P07~P00
 *	1 = GPIO mode; 0 = LED mode
 */
#define AW9523_SetP0Mode(mode)	AW9523_writeReg(0x12, (mode))

/*	set P1 mode GPIO/LED
 *	mode	: bit7~0 ---- P07~P00
 *	1 = GPIO mode; 0 = LED mode
 */
#define AW9523_SetP1Mode(mode)	AW9523_writeReg(0x13, (mode))

/*	set dim
 *	pin	: the pin to set
 *	dim	: dim value 0~255
 */
#define AW9523_SetDim(pin, dim)	AW9523_writeReg((pin),(dim))

/*	set Imax
 */
#define AW9523_SetImax(Imax)	AW9523_writeReg(0x11,(Imax))

aw_u8	AW9523_readReg(aw_u8 reg);
void 	AW9523_writeReg(aw_u8 reg, aw_u8 val);

#endif
